package com.anolesoft.amljmes.fortysix.service.impl;

import com.anolesoft.amljmes.fortysix.controller.MesBzzPtjhInfoController;
import com.anolesoft.amljmes.fortysix.dto.NewPtjhDto;
import com.anolesoft.amljmes.fortysix.dto.PtjhExport;
import com.anolesoft.amljmes.fortysix.service.info.MesBzzPtjhInfoService;
import com.anolesoft.amljmes.fortysix.service.mapper.MesBzzPtjhInfoServiceMapper;
import org.apache.ibatis.session.ExecutorType;
import org.apache.ibatis.session.SqlSession;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
/**
 * @author lx
 * @date 2022/11/21
 * 配套计划
 */
@Service
public class MesBzzPtjhInfoServiceImpl implements MesBzzPtjhInfoService {
    @Autowired
    MesBzzPtjhInfoServiceMapper mesBzzPtjhInfoServiceMapper;
    @Autowired
    private SqlSessionTemplate sqlSessionTemplate;

    @Override
    public List<NewPtjhDto> queryMesBzzPtjhInfo(MesBzzPtjhInfoController.DemoVO demoVO) {
        List<NewPtjhDto> queryMesBzzPtjhInfo=mesBzzPtjhInfoServiceMapper.queryMesBzzPtjhInfoSQL(demoVO);
        return queryMesBzzPtjhInfo;
    }
    @Override
    public List<NewPtjhDto> queryMesBzzPtjhInfo2(MesBzzPtjhInfoController.DemoVO demoVO) {
        List<NewPtjhDto> queryMesBzzPtjhInfo=mesBzzPtjhInfoServiceMapper.queryMesBzzPtjhInfoSQL2(demoVO);
        return queryMesBzzPtjhInfo;
    }

    @Override
    public int updatePtjh(NewPtjhDto inFoDtoParam) {
        int count = mesBzzPtjhInfoServiceMapper.updatePtjh(inFoDtoParam);
        return count;
    }

    @Override
    public int delete(List<String> objuids) {
        int count = 0;
        for(String objuid : objuids) {
            count += mesBzzPtjhInfoServiceMapper.delete(objuid);
        }
        return count;
    }

    @Override
    public void uploadExcel(List<NewPtjhDto> list) {
        SqlSession sqlSession = sqlSessionTemplate.getSqlSessionFactory().openSession(ExecutorType.BATCH, false);
        MesBzzPtjhInfoServiceMapper mesBzzPtjhInfoServiceMapper = sqlSession.getMapper(MesBzzPtjhInfoServiceMapper.class);
        list.forEach(a -> {
            mesBzzPtjhInfoServiceMapper.insert(a);
        });
        sqlSession.commit();
    }

    @Override
    public List<PtjhExport> exportPtjh(MesBzzPtjhInfoController.DemoVO demoVO) {
        List<PtjhExport> ptjh=mesBzzPtjhInfoServiceMapper.exportPtjh(demoVO);
        return ptjh;
    }

}
